package io.gitee.zhangbinhub.acp.core.common.security

import io.gitee.zhangbinhub.acp.core.common.base.BaseEncrypt
import org.bouncycastle.crypto.digests.SM3Digest

object SM3Encrypt : BaseEncrypt() {

    /**
     * 加密
     *
     * @param plainText 待加密字符串
     * @return 密文
     */
    @JvmStatic
    @JvmOverloads
    fun encrypt(
        plainText: String,
        inputEncode: ByteEncodeEnum = ByteEncodeEnum.BYTE,
        outputEncode: ByteEncodeEnum = ByteEncodeEnum.HEX
    ): String = SM3Digest().let { digest ->
        val plainBytes = decodeToBytes(plainText, inputEncode)
        digest.update(plainBytes, 0, plainBytes.size)
        val resultBytes = ByteArray(digest.digestSize)
        digest.doFinal(resultBytes, 0)
        encodeToString(resultBytes, outputEncode)
    }

}